<?php
require_once('config.inc.php');

page_open( array( 'sess' => 'MySession'
                , 'auth' => 'MyAuth'
                )
         );

page_close();

/**
 * Retourne un montant en euro, ou rien du tout
 */ 
function montant($montant)
{
  return $montant ? "$montant €" : '&nbsp;'; 
}

/**
 * FORMAT ROW OPERATION
 */ 
function print_row_operation($id, $date, $montant, $type, $cat, $infos, $num_cpte, $libelle)
{
print <<<EORO
  <tr id="op_$id">
    <td>$date</td>
    <td class="$type">$montant</td>
    <td>$cat</td>
    <td>n°$num_cpte ($libelle)</td></tr>

EORO;
}


// ACTIONS
switch (rd_get('action'))
{
case 'find':
  /// FIND
  $how = array();
  if (rd_get('by_date')    == 'on')  $how[] = 'date';
  if (rd_get('by_montant') == 'on')  $how[] = 'montant';
  if (rd_get('by_compte')  == 'on')  $how[] = 'compte';

  $what = array( 'date_min'    => DateSql::Fr2Sql(rd_get('date_min'))
               , 'date_max'    => DateSql::Fr2Sql(rd_get('date_max'))
               , 'montant_min' => rd_get('montant_min')
               , 'montant_max' => rd_get('montant_max')
               , 'id_compte'   => rd_get('compte')
               );

  $operations = Gestion::find_operations($auth->auth['uid'], $how, $what);
  foreach ($operations as $op)
  {
    print_row_operation( $op['id_operation']
                       , DateSql::Sql2Fr($op['date'])
                       , $op['montant']
                       , $op['type']
                       , $op['categorie']
                       , $op['infos']
                       , $op['numero_compte']
                       , $op['libelle_compte']
                       );
  }
  break;
}
?>
